package com.justech.eat.controller;


import com.justech.common.vo.PageDto;
import com.justech.eat.controller.req.OrderDayCount;
import com.justech.eat.controller.req.OrderDetailReq;
import com.justech.eat.entity.Order;
import com.justech.eat.entity.OrderDetailAbnormalRecord;
import com.justech.eat.mapper.mysql.OrderMapper;
import com.justech.eat.service.OrderMgrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * @program: eat-service
 * @description:
 * @author: feifei.li
 * @create: 2020-06-01 14:41
 **/

@RestController
@Validated
@RequestMapping("mgr/order")
public class OrderMgrController {
    @Autowired
    OrderMgrService OrderMgrService;
    @Autowired
    OrderMapper orderMapper;

    //批量添加报餐信息
    @RequestMapping("/submitOrders")
    public void submitOrders(@RequestBody @Valid List<OrderDetailReq> orderDetailReqs, String date, String jobNumber) {
        OrderMgrService.submitOrders(orderDetailReqs, date, jobNumber);
    }

     //提交报餐
    @RequestMapping("/submitOrder")
    public void submitOrder(@RequestBody @Valid OrderDetailReq orderDetailReqs, String date, String jobNumber) {
        OrderMgrService.submitOrder(orderDetailReqs, date, jobNumber);
    }

     //批量处理异常
    @RequestMapping("/explainOrderAbnormals")
    public void explainOrderAbnormals(@RequestBody @NotEmpty(message = "异常id不能为空") List<Long> abnormalIds, @NotBlank(message = "原因不能为空") String reason, @NotNull(message = "异常状态码不能为空") int reasonCode) {
        OrderMgrService.explainOrderAbnormals(abnormalIds, reason, reasonCode);
    }

     //处理异常
    @RequestMapping("/explainOrderAbnormal")
    public void explainOrderAbnormal(@NotNull(message = "异常id不能为空") Long abnormalId, @NotBlank(message = "原因不能为空") String reason,@NotNull(message = "异常状态码不能为空") int reasonCode) {
        OrderMgrService.explainOrderAbnormal(abnormalId, reason, reasonCode);
    }

     //异常列表
    @RequestMapping("/getAbnormalList")
    public PageDto<OrderDetailAbnormalRecord> getAbnormalList(@RequestBody OrderDetailAbnormalRecord params, long page, int size) {
        return OrderMgrService.getAbnormalList(params, page, size);

    }

    //报餐明细
    @RequestMapping("/getOrderList")
    public PageDto<Order> getOrderList(@RequestBody Order order, long page, int size) {
        return OrderMgrService.getOrderDetailList(order, page, size);
    }

    //报餐详情(包含每餐明细)
    @RequestMapping("/getOrderDetailList")
    public PageDto<Order> getOrderDetailList(@RequestBody Order order, long page, int size){
            return OrderMgrService.getOrderDetailList(order, page, size);
    }

     //查询当天各餐别的报餐数量
    @RequestMapping("/findAllDetail")
    public OrderDayCount findAllDetail() {
        return OrderMgrService.findAllDetail();
    }

}
